package com.myk.game.heroscuffle.heroes;

import com.myk.game.heroscuffle.game.Attacked;
import com.myk.game.heroscuffle.game.Element;
import com.myk.game.heroscuffle.game.Hero;
import com.myk.game.heroscuffle.utils.RdmPropUtil;

public class Hero_KuMeng extends Hero {

    /**
     * 生命值顶级，防御力非常高，攻击力偏低。
     * 每当场上有其它角色死亡时，hp就会增加，名为吸收能量，
     * 所以他会优先攻击血量最低的角色。
     */
    public Hero_KuMeng() {
        super("枯蒙",
                "会更加优先攻击生命值最低的敌人。当有其它英雄死亡时，枯蒙会根据他的元素属性吸收其剩余能量，恢复生命值和增加攻击力。",
                Element.DARK,
                1300, 125, 58);
    }

    @Override
    public void onAutoSelectAction() {
        Hero best = game.pool.getBestAliveHeroBy((challenged, challenger) -> {
            return Integer.compare(challenged.hp, challenger.hp); //借用Integer自带的api来返回1,0和-1。
        }, this);
        Hero anther = game.pool.getAnyoneAliveHero(this, best);
        if (anther != null) {
            if (RdmPropUtil.bingo(1 / 2d)) {
                doAttackActionStart(new Attacked(best, "垂涎欲滴扑向"));
            }
            else {
                doAttackActionStart(new Attacked(anther, "无缘无故随意攻击"));
            }
        }
        else {
            doAttackActionStart(new Attacked(best, "垂涎欲滴扑向"));
        }
    }

    @Override
    public void onSummon() {
        //当有其它英雄死亡时，枯蒙吸收他的剩余能量恢复一定的生命值
        game.events.onHeroDead.addRunBack(gameEventData -> {
            if (gameEventData.dead == this) {
                gameEventData.removeRunBackFromListener();
            }
            else {
                //增加生命值
                int hpAdd = 60;
                if (gameEventData.dead.ELE == Element.ICE) {
                    hpAdd += 20;
                }
                if (gameEventData.dead.ELE == Element.FLAME) {
                    hpAdd -= 20;
                }
                if (hp + hpAdd < HP) {
                    hp += hpAdd;
                    game.ui.printMsg(getObviousName() + "吸收了" + gameEventData.dead.getObviousName() + "剩余的能量,hp增加" + hpAdd + ",当前" + hp + "点。");
                }
                else {
                    int lastHpAdd = getHpUpTo();
                    hp += lastHpAdd;
                    game.ui.printMsg(getObviousName() + "吸收了" + gameEventData.dead.getObviousName() + "剩余的能量,hp增加" + lastHpAdd + ",当前" + hp + "点(已满)。");
                }
                //增加攻击力
                int atkAdd = 5;
                if (gameEventData.dead.ELE == Element.EARTH || gameEventData.dead.ELE == Element.WOOD) {
                    addAtkWithPrint(atkAdd);
                }
            }
        });
    }
}
